package com.bestv.search.common.dao.hibernate;

import com.bestv.search.common.dao.TypeDao;
import com.bestv.search.common.model.Type;

import java.util.List;

/**
 * @author Michael Wang
 */

// $Id$
public class TypeDaoHibernate extends GenericDaoHibernate<Type, Long> implements TypeDao {

    public TypeDaoHibernate() {
        super(Type.class);
    }

    @Override
    public Type getTypeById(Long id) {
        return super.get(id);
    }

    @SuppressWarnings("unchecked")
    @Override
    public Type getTypeByName(String name) {
        List<Type> types = getHibernateTemplate().find("from Type t where t.name = ?", name);
        if (types == null || types.size() == 0)
            return null;
        return types.get(0);
    }

    @Override
    public List<Type> getTypes() {
        return super.getAll();
    }

    @Override
    public Type saveType(Type type) {
        return super.save(type);
    }

    @Override
    public void deleteTypeById(Long id) {
        super.remove(id);
    }
}
